package cn.edu.sdjzu.xg.eagle.mapper;


import cn.edu.sdjzu.xg.eagle.entities.Material;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper


public interface MaterialMapper {

    @Insert("INSERT INTO Materials (MaterialName, StorageLocation, Status, TotalQuantity, StockQuantity) " +
            "VALUES (#{materialName}, #{storageLocation}, #{status}, #{totalQuantity}, #{stockQuantity})")
    @Options(useGeneratedKeys = true, keyProperty = "materialId", keyColumn = "MaterialId")
    boolean addMaterial(Material material);


    @Delete("DELETE FROM Materials WHERE MaterialId = #{materialId}")
    boolean deleteMaterial(Integer materialId);


    @Update("UPDATE Materials SET " +
            "MaterialName = #{materialName}, " +
            "StorageLocation = #{storageLocation}, " +
            "Status = #{status}, " +
            "TotalQuantity = #{totalQuantity}, " +
            "StockQuantity = #{stockQuantity} " +
            "WHERE MaterialId = #{materialId}")
    boolean updateMaterial(Material material);


    @Select("SELECT " +
            "m.MaterialId AS materialId, " +
            "m.MaterialName AS materialName, " +
            "m.StorageLocation AS storageLocation, " +
            "m.Status AS status, " +
            "m.TotalQuantity AS totalQuantity, " +
            "m.StockQuantity AS stockQuantity " +
            "FROM Materials m " +
            "WHERE m.MaterialId = #{materialId}")
    Material findMaterialById(Integer materialId);


    @Select("SELECT " +
            "m.MaterialId AS materialId, " +
            "m.MaterialName AS materialName, " +
            "m.StorageLocation AS storageLocation, " +
            "m.Status AS status, " +
            "m.TotalQuantity AS totalQuantity, " +
            "m.StockQuantity AS stockQuantity " +
            "FROM Materials m")
    List<Material> findMaterials();
}
